<?php 
			
if(!empty($_GET['userid'])){	
	$id = $_GET['userid'];
}
$db = include('../Application/Common/Conf/config.php');
		$host =  $db['DB_HOST'];
		$port =  $db['DB_PORT'];
		$dbname =  $db['DB_NAME'];
		$user =  $db['DB_USER'];
		$psw =  $db['DB_PWD'];
		$dbconn = pg_connect("host=$host port=$port dbname=$dbname user=$user password=$psw");	
		if($dbconn){
			$sql = "select ncash,nrate from tbrechargerate order by ncash DESC;";				
			$data = pg_query($dbconn,$sql);	
			$result = pg_fetch_all($data);
			$defalut_rate = $result[count($result)-1]['nrate'];			
			$rates = json_encode($result);			
		}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8;" />
<link href="css/style.css" type="text/css" rel="stylesheet">
<link  id="iepng" href="" type="text/css" rel="stylesheet">
<script>
   if(window.XMLHttpRequest)
    {
        document.getElementById('iepng').href="css/normal.css";
    }
</script>
<script type="text/javascript" src="../Public/js/jquery-1.11.0.min.js"></script>
<script>
function shortRMB(money){
		total = money.toString();
		if(total.length>4 && total.length<9){
			jinbi = total.substr(0,total.length-4);
			jinbi = jinbi+"万";
		}else if(total.length>8){
			jinbi = total.substr(0,total.length-8);
			xiaoshu = total.substr(1,total.length-8);
			if(xiaoshu!=0){
				jinbi = jinbi+"."+xiaoshu+"亿";	
			}else{
				jinbi = jinbi+"亿";	
			}			
		}	
		return jinbi;
	
}
	$(function(){	
		$(document).keypress(function(e) { 
          // 回车键事件 
		   if(e.which == 13) { 
				$('.charesure').trigger("click");
		   } 
         });		
		
		defalut_val = $("#choose").val();
		defalut_jinbi = defalut_val*<?php echo $defalut_rate;?>;
		$('#hjinbi').val(defalut_jinbi);
		$('#jinbi').text(shortRMB(defalut_jinbi));
		$('#money').text(defalut_val+'.0');
		
		$('#choose').change(function(){
			current = $(this).val();			
			rates = <?php echo $rates ;?>;
			for(i=0;i<rates.length;i++){				 
				if(parseInt(current)>=parseInt(rates[i].ncash)){
					rate = rates[i].nrate;
					break;					
				}								
			}
			totalJB = current*rate;
			$('#hjinbi').val(totalJB);
			$('#jinbi').text(shortRMB(totalJB));
			$('#money').text(current+".0");			
		
			

		});
		
	$('.charesure').click(function(){
		inid = $("input[name='account']").val();
		sure = $("input[name='sureid']").val();	
		if(inid==''){
			alert('请输入充值帐号');
			return false;
		}else if(sure==''){
			alert('请确认充值帐号');
			return false;
		}else if(inid!=sure){
			alert('两次帐号不一致');
			return false;
		}
	
		$.ajax({
		 type: "POST",
		 url: "checkid.php",
		 data: {inid:inid},
		 dataType: "text",
		 success: function(data){
				if(data!=1){
					$('#username').val(data);
					$("form[name='payment']").submit();
				}else{
					alert('此帐号不存在');
				}
			}
		})		
			
	})

	})
</script>
</head>
<body>
<div class="charge_wrap">
	<?php include 'left.php';?>

	<div class="chargeMain">
		<div class="chargeTitle"><span>网银充值金币</span></div>
		<div class="step"><img src="../Public/img/step1.jpg" /></div>
		<form method="post"  name="payment" action='sure.php' >
			<ul class="chareform">
				<li><label>充值帐号：</label><input type="text" name="account"  value="<?php echo $id;?>" /></li>
				<li><label>确认帐号：</label><input type="text" name="sureid"  value="<?php echo $id;?>" /></li>
				<li class="chareqty">
				<label>充值数量：</label>
				<select name="choose" id="choose">
					<option value='10'>10元</option>
					<option value='20'>20元</option>
					<option value='30'>30元</option>
					<option value='50'>50元</option>
					<option value='60'>60元</option>
					<option value='70'>70元</option>
					<option value='80'>80元</option>
					<option value='90'>90元</option>
					<option value='100'>100元</option>
					<option value='200'>200元</option>
					<option value='300'>300元</option>
					<option value='500'>500元</option>
					<option value='600'>600元</option>
					<option value='700'>700元</option>
					<option value='800'>800元</option>
					<option value='900'>900元</option>
					<option value='1000'>1000元</option>
					<option value='2000'>2000元</option>
					<option value='3000'>3000元</option>
					<option value='5000'>5000元</option>
				</select>
				<i>(等于<a id="jinbi"></a>金币，提示：充值越多折扣越大)</i>
				</li>
				<li><label>应付金额：</label><span id="money"></span>元</li>
				<li class="charesure">下一步</li>
			</ul>
			<input type="hidden" name="username" id="username"  />
			<input type="hidden" name="hjinbi" id="hjinbi" />
		</form>
		<div class="iconDetail">
			<h3>财富图标说明</h3>
			<table class="iconItem" cellspacing=0 cellpadding=0>
				<tr>
					<td><strong>财富范围</strong></td>
					<td><strong>财富图标</strong></td>
				</tr>
				<tr>
					<td>0至9999</td>
					<td><img src="../Public/img/caifu1.jpg" /></td>
				</tr>
				<tr>
					<td>10000至99999</td>			
					<td><img src="../Public/img/caifu2.jpg" /></td>
				</tr>
				<tr>
					<td>100000至999999</td>
					<td><img src="../Public/img/caifu3.jpg" /></td>				
				</tr>
				<tr>
					<td>1000000至4999999</td>
					<td><img src="../Public/img/caifu4.jpg" /></td>				
				</tr>	
				<tr>
					<td>5000000至9999999</td>
					<td><img src="../Public/img/caifu5.jpg" /></td>				
				</tr>	
				<tr>
					<td>10000000以上</td>
					<td><img src="../Public/img/caifu6.jpg" /></td>				
				</tr>					
			</table>			
		</div>
	</div>
	
	<div style="clear:both"></div>
	<div style="width:100%;height:15px;background:#fff;"></div>

</div>
</body>
</html>